const router = require('koa-router')()
const wordAPI = require('../controllers/word')

router
  .get('/api/word/list', async(ctx, next) => { // 全部词库
    let query = ctx.request.query
    let data = await wordAPI.list(query)
    ctx.body = data
  })
  .get('/api/word', async(ctx, next) => { // 你划我猜词库
    ctx.body = await wordAPI.guess()
  })
  .get('/api/guess', async(ctx) => { // 你画我猜词库
    ctx.body = await wordAPI.guess()
  })
  .get('api/undercover', async(ctx) => { // 谁是卧底词库
    ctx.body = await wordAPI.undercover()
  })
  .post('/api/word', async(ctx, next) => {
    ctx.body = await wordAPI.insert(ctx.request.body.words)
  })
  .delete('/api/word', async(ctx, next) => {
    let data = await wordAPI.delete(ctx.request.body.ids)
    ctx.body = data
  })
  .put('/api/word/:id', async(ctx) => {
    ctx.body = await wordAPI.update(ctx.params.id, ctx.request.body)
  })
  module.exports = router